//2671.频率跟踪器
//https://leetcode.cn/problems/frequency-tracker/?envType=daily-question&envId=2024-03-21
class FrequencyTracker {
    unordered_map<int,int> hash;
    unordered_map<int,int> cnt;
public:
    FrequencyTracker() {}
    
    void add(int number) {
        if(hash.count(number)) 
        {
            --cnt[hash[number]];
            if(cnt[hash[number]] == 0) cnt.erase(hash[number]);
        }
        ++hash[number];
        ++cnt[hash[number]];
    }
    
    void deleteOne(int number) {
        if(hash.count(number))
        {
            --cnt[hash[number]];
            if(cnt[hash[number]] == 0) cnt.erase(hash[number]);
            --hash[number];
            if(hash[number] == 0) hash.erase(number);
            else ++cnt[hash[number]];
        }
    }
    
    bool hasFrequency(int frequency) {
        if(cnt.count(frequency)) return true;
        return false;
    }
};